
pkgname=iptables
pkgver=1.6.2
pkgrel=1
pkgdesc="A Linux kernel packet control tool"
arch=('x86_64')
license=('GPL2')
url='https://www.netfilter.org/projects/iptables/index.html'
depends=('glibc' 'bash')
makedepends=('linux-api-headers' 'chrpath')
options=('!libtool')
source=("https://www.netfilter.org/projects/iptables/files/${pkgname}-${pkgver}.tar.bz2"
        'empty.rules'
        'simple_firewall.rules'
        'empty-filter.rules'
        'empty-mangle.rules'
        'empty-nat.rules'
        'empty-raw.rules'
        'empty-security.rules'
        'iptables.service'
        'ip6tables.service'
        'iptables-flush')
sha1sums=('6279effbf8f2c7ff53d19ae13308f8a6e6a60dd9'
          '83b3363878e3660ce23b2ad325b53cbd6c796ecf'
          'f085a71f467e4d7cb2cf094d9369b0bcc4bab6ec'
          'd9f9f06b46b4187648e860afa0552335aafe3ce4'
          'c45b738b5ec4cfb11611b984c21a83b91a2d58f3'
          '1694d79b3e6e9d9d543f6a6e75fed06066c9a6c6'
          '7db53bb882f62f6c677cc8559cff83d8bae2ef73'
          'ebbd1424a1564fd45f455a81c61ce348f0a14c2e'
          '5f2e76985a751f635a45612565a6e1bc9547398a'
          'fe6bbe214b3a13bd084f62a8ee9631fd8326c464'
          'e7abda09c61142121b6695928d3b71ccd8fdf73a')

build() {
  cd ${pkgname}-${pkgver}

  rm include/linux/types.h

 ./configure --prefix=/usr \
     --libexecdir=/usr/lib/iptables \
     --sysconfdir=/etc \
     --with-xtlibdir=/usr/lib/iptables \
     --enable-devel \
     --enable-shared \
     --disable-nftables
  make
}

package() {
  cd ${pkgname}-${pkgver}

  make DESTDIR=${pkgdir} install

  # http://www.spinics.net/lists/netfilter-devel/msg24969.html
  chrpath --delete ${pkgdir}/usr/lib/iptables/*.so

  cd ${srcdir}
  install -D -m644 empty.rules ${pkgdir}/etc/iptables/empty.rules
  install -D -m644 simple_firewall.rules ${pkgdir}/etc/iptables/simple_firewall.rules

  mkdir -p ${pkgdir}/var/lib/{iptables,ip6tables}
  install -m644 empty-{filter,mangle,nat,raw,security}.rules ${pkgdir}/var/lib/iptables
  install -m644 empty-{filter,mangle,nat,raw,security}.rules ${pkgdir}/var/lib/ip6tables

  # systemd 
  install -Dm644 ${srcdir}/iptables.service ${pkgdir}/usr/lib/systemd/system/iptables.service
  install -Dm644 ${srcdir}/ip6tables.service ${pkgdir}/usr/lib/systemd/system/ip6tables.service
  install -Dm755 ${srcdir}/iptables-flush ${pkgdir}/usr/lib/systemd/scripts/iptables-flush  
}
